package com.cxrj.zhsq.propertyManage.controller;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cxrj.zhsq.annotation.SystemControllerLog;
import com.cxrj.zhsq.propertyManage.entity.Notice;
import com.cxrj.zhsq.propertyManage.service.NoticeSecvice;

@Controller
@RequestMapping("/notice")
public class NoticeController {
	
	@Resource
	private NoticeSecvice noticeSecvice;
	
	/**
	 * 插入公告
	 * @param notice
	 * @return
	 */
	@RequestMapping("insertNotice")
	@SystemControllerLog(description = "添加社区公告")
	@ResponseBody
	public Map<String, Object> insertNotice(Notice notice){
		Map<String, Object> resultMap=new HashMap<>();
		try {
			noticeSecvice.insertNotice(notice);
			resultMap.put("result", "1");
		} catch (Exception e) {
			resultMap.put("result", "-1");
			e.printStackTrace();
		}
		return resultMap;
	}
	/**
	 * 编辑公告
	 * @param notice
	 * @return
	 */
	@RequestMapping("updateNotice")
	@ResponseBody
	public Map<String, Object> updateNotice(Notice notice){
		
		return noticeSecvice.updateNotice(notice);
	}
	/**
	 * 分页查询公告
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "selectNoticePage", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	public Map<String, Object> selectNoticePage(HttpServletRequest request,HttpServletResponse response){
		return noticeSecvice.selectNoticePage(request,response);
	}
	/**
	 * 根据ID查询
	 * @param noticeId
	 * @return
	 */
	@RequestMapping(value = "selectById", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	public Map<String, Object> selectById(String noticeId, HttpServletRequest request){
		return noticeSecvice.selectById(noticeId, null, request);
	}
	
	/**
	 * 删除公告
	 * @param noticeId
	 * @param noticeImg
	 * @return
	 */
	@RequestMapping(value = "deleteNotice")
	@SystemControllerLog(description = "删除社区公告")
	@ResponseBody
	public Map<String, Object> deleteNotice(String noticeId,HttpServletRequest request,HttpServletResponse response){
		return noticeSecvice.deleteNotice(noticeId,request,response);
	}
	/**
	 * 发布或取消发布
	 * @param noticeId
	 * @param noticeImg
	 * @return
	 */
	@RequestMapping(value = "releaseNotice")
	@ResponseBody
	public Map<String, Object> updatereleaseNotice(String noticeId,String noticeState){
		return noticeSecvice.updatereleaseNotice(noticeId,noticeState);
	}

}
